package com.kingint.web.portal.serve.controller;


import com.kingint.mbg.group.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.portal.serve.service.CheckRoomService;
import com.kingint.mbg.ser.entity.SerCheckRoom;

import java.util.List;


/**
 * @描述：查房工单详情表控制类
 * @作者: wxh
 * @日期: 2020-12-24
 */
@RestController
@RequestMapping("/CheckRoom")
@Api(value = "CheckRoomController", description = "查房工单详情表")
@CrossOrigin
public class CheckRoomController {

    @Autowired
    public CheckRoomService checkRoomService;


    @ApiOperation(value = "添加查房工单详情表")//前端自己创建使用
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody SerCheckRoom serCheckRoom){
        return checkRoomService.addCheckRoomOder(serCheckRoom) ? K.ok().data("成功") : K.error().data("失败");
    }

    @ApiOperation(value = "接受并完成查房工单（后台创建，前端接受时使用）")
    @GetMapping("/accept")
    public Object accept(@RequestParam("id") Integer id){
        return checkRoomService.acceptCheckRoomOder(id) ? K.ok().data("成功") : K.error().data("失败");
    }

    @ApiOperation(value = "完成查房工单（后台创建，前端接受时使用）")
    @PostMapping("/completeforfront")
    public Object completeforfront(@Validated(Insert.class) @RequestBody SerCheckRoom serCheckRoom){
        return checkRoomService.completeCheckRoomOder(serCheckRoom) ? K.ok().data("成功") : K.error().data("失败");
    }


    @ApiOperation(value = "根据编号查询查房工单详情表信息")
    @GetMapping("/{id}")
    public Object getItem(@PathVariable("id") Integer id){
        SerCheckRoom serCheckRoom = checkRoomService.getonebyid(id);
        return K.ok().data(serCheckRoom);
    }


//    @ApiOperation(value = "根据查房工单详情表名称分页获取查房工单详情表列表")
//    @GetMapping("/listAll")
//    public Object getListAll(){
//        List<SerCheckRoom> serCheckRoomList = checkRoomService.getCheckRoomOder();
//        return K.ok().data(serCheckRoomList);
//    }

}